<?php

namespace App\Services\Common;

use Cache;
use Carbon\Carbon;

class CacheService extends BaseService
{
    /**
     * 开启缓存
     * @param $key
     * @param $id
     * @return bool
     */
    public static function startCache($key, $id)
    {
        $key_object = sprintf($key, $id);
        return \Cache::add($key_object, true, Carbon::now()->addMinute());
    }

    /**
     * 清除缓存
     * @param $key
     * @param $val
     */
    public static function clearCache($key, $val)
    {
        try {
            Cache::delete(sprintf($key, $val));
        } catch (\Psr\SimpleCache\InvalidArgumentException $e) {
        }
    }
}
